var data;
//获取待处理事务信息
getPendingTransactions();
//获取echarts数据
getDataEcharts("getProductDay");

//商品统计
getChangeDateEcharts('product');
function getChangeDateEcharts(tabName) {
    getNowMonthCourseNums('getNowMonthProductNums','本月新增商品总数');
    getDataEcharts("getProductDay","商品统计","商品量");
}

function getNowMonthCourseNums(request, monthTypeName) {
    $.ajax({
        url: '/systemIndex/' + request,
        type: 'post',
        dataType:'json',
        data: {},
        success:function (data) {
            $('#monthTypeName').text(monthTypeName);
            $('#monthSum').text(data.data.nowMonthProductNums);
            var monthSumRate = Math.round((data.data.nowMonthProductNums - data.data.lastMonthProductNums) / data.data.lastMonthProductNums * 100);
            $('#monthSumRate').text(monthSumRate + "%");
        }
    });
}

function getPendingTransactions() {
    $.ajax({
        url:'/systemIndex/getSystemIndexOperateNums',
        method:'post',
        data:{},
        dataType:'json',
        success: function (item) {
            data = item.data;
            console.log(data);
            $("#productCount").text(data.commodityNums);
            $("#productCountTwo").text(data.commodityNums);
            $("#commoditySaleNums").text(data.commoditySaleNums);
            $("#commoditySaleNumsTwo").text(data.commoditySaleNums);
            $("#commodityCollectionNums").text(data.commodityCollectionNums);
            $("#completedOrder").text(data.completedOrder);
            $("#completedOrderTwo").text(data.completedOrder);
            $("#product_to_examine").text(data.commodityNoNums);
            $("#course_to_examine").text(data.courseNoNums);
            $("#returnOrderCount").text(data.returnRequest);
            $("#orderQuantityNums").text(data.orderQuantityNums);
        }
    })
}

function getDataEcharts(request, name,typename) {
    $.ajax({
        url: '/systemIndex/' + request,
        type: 'post',
        dataType:'json',
        data: {},
        success:function (data) {
            $("#statistics").text(name);
            getEcharts(data.data.data, data.data.list,typename);
        }
    });
}

//展示echarts图
function getEcharts(data, list, typename) {
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('linear'));
    // 指定图表的配置项和数据
    var option = {
        tooltip: {},
        legend: {
            data: [typename],
            bottom: 10
        },
        xAxis: {
            data: list
        },
        yAxis: {},
        series: [
            {
                name: typename,
                type: 'line',
                data: data,
                // 点的颜色。
                itemStyle: {color: 'rgb(13, 171, 158)'},
            }
        ]
    };
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
}

function load() {
    location.reload();
}

function jump() {

}